package com.springmvc.platform.base.datasource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * @author 数据源动态切换实现读写分离
 * @create 2017/11/6
 * @modify
 */
public class DynamicDataSource extends AbstractRoutingDataSource {
    private final static Logger _log = LoggerFactory.getLogger(DynamicDataSource.class);

    @Override
    protected Object determineCurrentLookupKey() {
        String dataSource = DataSourceContextHolder.getDataSource();
        _log.info("当前操作使用的数据源：{}", dataSource);
        return dataSource;
    }
}
